﻿using ZYCommon;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace TextEditor
{
    

    /// <summary>
    /// 设置默认字体
    /// </summary>
    public class A_SetDefaultFont : A_Action
    {
        public override string ActionName()
        {
            return "setdefaultfont";
        }

        public override bool Execute()
        {
            if (StringCommon.HasContent(base.Param1))
            {
                string familyName = base.Param1;
                float size = base.myOwnerDocument.View.DefaultFont.Size;
                if (StringCommon.IsNumberic(base.Param2))
                {
                    size = Convert.ToSingle(base.Param2);
                }
                base.myOwnerDocument.View.DefaultFont = new Font(familyName, size);
                base.myOwnerDocument.RefreshSize();
                base.myOwnerDocument.RefreshLine();
                base.myOwnerDocument.Refresh();
                return true;
            }
            return false;
        }

        public override bool UIExecute()
        {
            using (FontDialog dialog = new FontDialog())
            {
                dialog.Font = base.myOwnerDocument.View.DefaultFont;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    base.myOwnerDocument.View.DefaultFont = dialog.Font;
                    base.myOwnerDocument.RefreshSize();
                    base.myOwnerDocument.RefreshLine();
                    base.myOwnerDocument.Refresh();
                    return true;
                }
            }
            return false;
        }
    }
}

